package com.lzh.seatrend.common.entity;

/**
 * @Classname MyThreadLocal
 * @Description 当我们在创建一个变量后，如果每个线程对其进行访问的时候访问的都是线程自己的变量这样就不会存在线程不安全问题。
 * @Date 2021/10/28 14:03
 * @Created by liuzihao
 */
public class MyThreadLocal {
    static ThreadLocal<String> nameLocal = new ThreadLocal<>();

    public static void setNameLocal(String nameLocal){
        MyThreadLocal.nameLocal.set(nameLocal);
    }
    public static String getNameLocal(){
        return nameLocal.get();
    }
    static ThreadLocal<String> opDescribe = new ThreadLocal<>();
    static ThreadLocal<String> opConditionLocal = new ThreadLocal<>();
    static ThreadLocal<String> resultLocal = new ThreadLocal<>();

    /**
     * 删除当前线程的工作单元，避免内存泄露
     */
    public static void clean() {
        nameLocal.remove();
    }
    public static void setOpDescribe(String opDescribe) {
        MyThreadLocal.opDescribe.set(opDescribe);
    }
    public static void setOpConditionLocal(String opConditionLocal){
        MyThreadLocal.opConditionLocal.set(opConditionLocal);
    }

    public static void setResultLocal(ThreadLocal<String> resultLocal) {
        MyThreadLocal.resultLocal = resultLocal;
    }
}
